<template>
    <div class="flexbox flexcolumn over_box height_100">
        <BudgetModel />
        <AddBulkBid />
        <AudienceModel />
        <SaveModelName />
        <AddMateri :dataForm="dataForm" />
        <EditMateri />
        <AddPicture />
        <EditPicture />
        <EditCardInfo />
        <AddMoreWord :keywords="keyWordList" />
        <BatchAddIndustry />
        <IndustryModel />
        <CreatTitleModel />
        <BatchAddCreatTitle :keyWordList="keyWordList" :dataForm="dataForm" />
        <BatchAddTitle :keyWordFour="keyWordFour" :keyWordList="keyWordList" />
        <div class="adver_box over_box flex">
            <HeadStep :dataForm="dataForm" />
            <el-form ref="createform" :model="createform" :rules="createRules" label-position="top" class="create_form" :hide-required-asterisk='true'>
                <!-- 投放设置 -->
                <div class="com_box pd_20 no_radius" style="display:block">
                    <CreateType :dataForm="dataForm" @sessionSave="sessionSave" />
                    <div class="market_title">投放设置<!--{{isShowCoupon}} --></div>
                    <el-form-item label="转化目标" prop="external_action" :rules="{required: true, message: '请选择转化目标', trigger: ['blur', 'change']}" style="margin-bottom:0">
                        <el-radio-group v-model="createform.external_action" @change="changeExternal" class="create_radio" style="width:834px">
                            <el-radio label="AD_CONVERT_TYPE_LIVE_ENTER_ACTION">
                                <div class="flexbox flexcenter conversion_type">
                                    <img src="../../assets/img/market_checked.svg" alt="" class="conversion_check">
                                    <img src="../../assets/img/conversion_icon4.svg" alt="" class="conversion_img">
                                    <div class="conversion_info">
                                        <div class="conversion_name">进入直播间</div>
                                        <div class="conversion_text">更多人进入直播间</div>
                                    </div>
                                </div>
                            </el-radio>
                            <el-radio label="AD_CONVERT_TYPE_LIVE_CLICK_PRODUCT_ACTION">
                                <div class="flexbox flexcenter conversion_type">
                                    <img src="../../assets/img/market_checked.svg" alt="" class="conversion_check">
                                    <img src="../../assets/img/conversion_icon5.svg" alt="" class="conversion_img">
                                    <div class="conversion_info">
                                        <div class="conversion_name">直播间商品点击</div>
                                        <div class="conversion_text">更多人点击商品</div>
                                    </div>
                                </div>
                            </el-radio>
                            <el-radio label="AD_CONVERT_TYPE_LIVE_SUCCESSORDER_ACTION">
                                <div class="flexbox flexcenter conversion_type">
                                    <img src="../../assets/img/market_checked.svg" alt="" class="conversion_check">
                                    <img src="../../assets/img/conversion_icon6.svg" alt="" class="conversion_img">
                                    <div class="conversion_info">
                                        <div class="conversion_name">直播间下单</div>
                                        <div class="conversion_text">更多人下单商品</div>
                                    </div>
                                </div>
                            </el-radio>
                            <el-radio label="AD_CONVERT_TYPE_LIVE_SUCCESSORDER_PAY" v-if="createform.external_action!='AD_CONVERT_TYPE_LIVE_SUCCESSORDER_PAY_7DAYS'">
                                <div class="flexbox flexcenter conversion_type">
                                    <img src="../../assets/img/market_checked.svg" alt="" class="conversion_check">
                                    <img src="../../assets/img/conversion_icon7.svg" alt="" class="conversion_img">
                                    <div class="conversion_info">
                                        <div class="conversion_name">直播间成交</div>
                                        <div class="conversion_text">更多人支付订单</div>
                                    </div>
                                </div>
                            </el-radio>
                            <el-radio label="AD_CONVERT_TYPE_LIVE_SUCCESSORDER_PAY_7DAYS" v-if="createform.external_action=='AD_CONVERT_TYPE_LIVE_SUCCESSORDER_PAY_7DAYS'">
                                <div class="flexbox flexcenter conversion_type">
                                    <img src="../../assets/img/market_checked.svg" alt="" class="conversion_check">
                                    <img src="../../assets/img/conversion_icon7.svg" alt="" class="conversion_img">
                                    <div class="conversion_info">
                                        <div class="conversion_name">直播间成交</div>
                                        <div class="conversion_text">更多人支付订单</div>
                                    </div>
                                </div>
                            </el-radio>
                            <el-radio label="AD_CONVERT_TYPE_NEW_FOLLOW_ACTION">
                                <div class="flexbox flexcenter conversion_type">
                                    <img src="../../assets/img/market_checked.svg" alt="" class="conversion_check">
                                    <img src="../../assets/img/conversion_icon8.svg" alt="" class="conversion_img">
                                    <div class="conversion_info">
                                        <div class="conversion_name">直播间粉丝提升</div>
                                        <div class="conversion_text">更多人关注抖音号</div>
                                    </div>
                                </div>
                            </el-radio>
                            <el-radio label="AD_CONVERT_TYPE_LIVE_COMMENT_ACTION">
                                <div class="flexbox flexcenter conversion_type">
                                    <img src="../../assets/img/market_checked.svg" alt="" class="conversion_check">
                                    <img src="../../assets/img/conversion_icon9.svg" alt="" class="conversion_img">
                                    <div class="conversion_info">
                                        <div class="conversion_name">直播间评论</div>
                                        <div class="conversion_text">更多人在直播间评论</div>
                                    </div>
                                </div>
                            </el-radio>
                            <el-radio label="AD_CONVERT_TYPE_LIVE_SUCCESSORDER_SETTLE">
                                <div class="flexbox flexcenter conversion_type">
                                    <img src="../../assets/img/market_checked.svg" alt="" class="conversion_check">
                                    <img src="../../assets/img/conversion_icon10.svg" alt="" class="conversion_img">
                                    <div class="conversion_info">
                                        <div class="conversion_name">直播间结算</div>
                                        <div class="conversion_text">更多人完成结算</div>
                                    </div>
                                </div>
                            </el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <!-- <el-form-item v-if="createform.external_action == 'AD_CONVERT_TYPE_LIVE_ENTER_ACTION' ||  createform.external_action == 'AD_CONVERT_TYPE_LIVE_CLICK_PRODUCT_ACTION'" style="margin-bottom:0">
                        <el-checkbox v-model="createform.deep_external_action" :disabled="createform.delivery.cost_control" true-label="AD_CONVERT_TYPE_LIVE_SUCCESSORDER_ACTION" false-label="" @change="sessionSave">期望同时优化「直播间下单」</el-checkbox>
                    </el-form-item> -->
                    <div class="flexbox flexcenter" v-if="createform.external_action == 'AD_CONVERT_TYPE_LIVE_SUCCESSORDER_PAY' || createform.external_action=='AD_CONVERT_TYPE_LIVE_SUCCESSORDER_PAY_7DAYS'">
                        <el-form-item style="margin-bottom:0">
                            <el-checkbox v-model="createform.deep_external_action" :disabled="createform.delivery.cost_control || createform.delivery.smart_bid_type=='SMART_BID_CONSERVATIVE'" true-label="AD_CONVERT_TYPE_LIVE_PAY_ROI" false-label="" @change="payRoi">支付ROI</el-checkbox>
                        </el-form-item>
                        <template v-if="createform.deep_external_action=='AD_CONVERT_TYPE_LIVE_PAY_ROI'">
                            <el-form-item style="margin-bottom:0;margin-left:10px" prop="deep_bid_type" :rules="{required: true, message: '请选择', trigger: ['blur', 'change']}">
                                <el-checkbox v-model="createform.deep_bid_type" true-label="MIN" disabled false-label="" @change="sessionSave">深度出价方式</el-checkbox>
                            </el-form-item>
                            <span class="font_14 color_01" style="margin-left:10px;margin-right:5px">支付ROI目标</span>
                            <el-form-item style="margin-bottom:0" prop="roi_goal" :rules="createRules.checkRoi">
                                <el-input placeholder="最多支持两位小数，0.01～100" style="width:215px" @change="sessionSave" v-model="createform.roi_goal" size="small">
                                </el-input>
                            </el-form-item>
                            <span class="user_tips font_12 color_02">Tips：请自行确认账号是否拥有此功能</span>
                        </template>
                    </div>
                    <el-form-item label="优化周期" prop="external_action" :rules="{required: true, message: '请选择', trigger: ['blur', 'change']}" v-if="createform.external_action=='AD_CONVERT_TYPE_LIVE_SUCCESSORDER_PAY'||createform.external_action=='AD_CONVERT_TYPE_LIVE_SUCCESSORDER_PAY_7DAYS'" style="margin-top:12px">
                        <el-radio-group v-model="createform.external_action" size="small" @change="changeRoiType">
                            <el-radio-button label="AD_CONVERT_TYPE_LIVE_SUCCESSORDER_PAY">{{createform.deep_external_action=="AD_CONVERT_TYPE_LIVE_PAY_ROI"?"直接支付ROI":"直接成交"}}</el-radio-button>
                            <el-radio-button label="AD_CONVERT_TYPE_LIVE_SUCCESSORDER_PAY_7DAYS">{{createform.deep_external_action=="AD_CONVERT_TYPE_LIVE_PAY_ROI"?"7日总支付ROI":"7日总成交"}}</el-radio-button>
                        </el-radio-group>
                    </el-form-item>
                </div>

                <!-- 预算和出价 -->
                <div class="com_box pd_20 mt_12" style="display:block">
                    <div class="market_title">预算和出价</div>
                    <BudgetList ref="budRef" :createform="createform" @changePlanKey="changePlanKey" @saveModel="saveModel" @sessionSave="sessionSave" />
                    <el-form-item label="投放方式" :prop="`delivery.smart_bid_type`" style="margin-bottom:0">
                        <div class="flexbox flexcenter">
                            <el-radio-group v-model="createform.delivery.smart_bid_type" class="create_radio" @change="changeSmartType">
                                <el-radio label="SMART_BID_CUSTOM">
                                    <div class="flexbox flexjust flexcolumn launch_type">
                                        <img src="../../assets/img/market_checked.svg" alt="" class="conversion_check">
                                        <div class="launch_name">控制成本投放</div>
                                        <div class="launch_text">控制成本，尽量消耗预算</div>
                                    </div>
                                </el-radio>
                                <el-radio label="SMART_BID_CONSERVATIVE" :disabled="createform.lab_ad_type=='LAB_AD'">
                                    <div class="flexbox flexjust flexcolumn launch_type">
                                        <img src="../../assets/img/market_checked.svg" alt="" class="conversion_check">
                                        <div class="launch_name">放量投放</div>
                                        <div class="launch_text">尽量消耗更多预算，接受成本上浮</div>
                                    </div>
                                </el-radio>
                            </el-radio-group>
                        </div>
                    </el-form-item>
                    <template v-if="createform.delivery.smart_bid_type=='SMART_BID_CUSTOM'">
                        <el-form-item :prop="`delivery.cost_control`">
                            <el-checkbox v-model="createform.delivery.cost_control" @change="changeCostControl">严格控制成本上限</el-checkbox>
                        </el-form-item>
                        <el-form-item label="投放速度" :prop="`delivery.flow_control_mode`" v-if="!createform.delivery.cost_control">
                            <el-radio-group v-model="createform.delivery.flow_control_mode" size="small" @change="sessionSave">
                                <el-radio-button label="FLOW_CONTROL_MODE_FAST">尽快投放</el-radio-button>
                                <el-radio-button label="FLOW_CONTROL_MODE_BALANCE">均匀投放</el-radio-button>
                            </el-radio-group>
                        </el-form-item>
                    </template>
                    <ReleaseDate :createform="createform" :dataForm="dataForm" @sessionSave="sessionSave" />
                    <ReleaseDuration :createform="createform" @sessionSave="sessionSave" v-if="createform.delivery.video_schedule_type=='SCHEDULE_TIME_FIXEDRANGE'" />
                    <DateRange :createform="createform" @sessionSave="sessionSave" v-if="createform.delivery.video_schedule_type=='SCHEDULE_START_END'" />
                    <LaunchPeriod :createform="createform" @sessionSave="sessionSave" v-if="createform.delivery.video_schedule_type !='SCHEDULE_TIME_FIXEDRANGE'" />
                    <TimeSlot v-if="createform.delivery.launch_period==2" v-model="createform.delivery.schedule_time_value" @change="sessionSave" />
                    <BudgetDay :createform="createform" @sessionSave="sessionSave" />
                    <BudgetPrice :createform="createform" @sessionSave="sessionSave" v-if="createform.delivery.smart_bid_type=='SMART_BID_CUSTOM'&&createform.deep_external_action==''" />
                    <Coupon :is_coupon="is_coupon" :createform="createform" @sessionSave="sessionSave" v-if="isShowCoupon" />
                </div>

                <!-- 定向人群 -->
                <div class="com_box pd_20 mt_12" style="display:block">
                    <div class="market_title">定向人群</div>
                    <AudienceList ref="audienceRef" :createform="createform" @changePlanKey="changePlanKey" @saveModel="saveModel" @sessionSave="sessionSave" />
                    <AudienceArea :createform="createform" :cityOptions="cityOptions" :countyOptions="countyOptions" @sessionSave="sessionSave" />
                    <AudienceNews :createform="createform" @sessionSave="sessionSave" />
                    <AudienceSex :createform="createform" @sessionSave="sessionSave" />
                    <AudienceAge :createform="createform" @sessionSave="sessionSave" />
                    <AudienceTalent :createform="createform" :titokResh="titokResh" :talentLoadding="talent_loadding" :titokLoadding="titok_loadding" @sessionSave="sessionSave" @getAwemecategory="getAwemecategory" @getRecommendedTalent="getRecommendedTalent" @remoteMethodTitok="remoteMethodTitok" />
                    <AudienceCrowd ref="crowdRef" :createform="createform" :pt_loadding="pt_loadding" :zdy_loadding="zdy_loadding" @getPlamCrow="getPlamCrow" @getCustomCrow="getCustomCrow" @sessionSave="sessionSave" />
                    <AudienceExtend :createform="createform" @sessionSave="sessionSave" />
                    <AudiencePlatform :createform="createform" @sessionSave="sessionSave" />
                    <AudienceIntention :dataForm="dataForm" :createform="createform" @sessionSave="sessionSave" />
                    <AudienceNetwork :createform="createform" @sessionSave="sessionSave" />
                </div>

                <!-- 制作创意 -->
                <div class="com_box pd_20 mt_12" style="display:block">
                    <div class="market_title">制作创意</div>
                    <CreativeList :createform="createform" @changePlanKey="changePlanKey" @sessionSave="sessionSave" v-if="createform.creative_way=='VIDEO'" />
                    <CreativeWay :createform="createform" @changeCreativeWay="changeCreativeWay" />
                    <template v-if="createform.creative_way=='VIDEO'">
                        <CreativeType :createform="createform" :dataForm="dataForm" @changeCreativeMode="changeCreativeMode" />
                        <CreativeContent :createform="createform" :dataForm="dataForm" :createRules="createRules" :keyWordFour="keyWordFour" :keyWordList="keyWordList" @sessionSave="sessionSave" />
                        <CreativeHide :createform="createform" :dataForm="dataForm" @sessionSave="sessionSave" />
                    </template>
                </div>

                <!-- 创意标题 -->
                <div class="com_box pd_20 mt_12" style="display:block" v-if="createform.creative_material_mode=='PROGRAMMATIC_CREATIVE'">
                    <div class="market_title">创意标题</div>
                    <TitleList ref="titleRef" :createform="createform" @sessionSave="sessionSave" @changePlanKey="changePlanKey" @saveModel="saveModel" />
                    <TitleContent :createform="createform" :dataForm="dataForm" :createRules="createRules" :keyWordFour="keyWordFour" @changeWordTitle="changeWordTitle" @sessionSave="sessionSave" />
                </div>

                <!-- 创意分类 -->
                <div class="com_box pd_20 mt_12" style="display:block">
                    <div class="market_title">创意分类</div>
                    <ClassifyList ref="classRef" :createform="createform" @changePlanKey="changePlanKey" @saveModel="saveModel" @sessionSave="sessionSave" />
                    <ClassifyType :createform="createform" :industryList="industryList" @sessionSave="sessionSave" />
                    <ClassifyTag :createform="createform" @sessionSave="sessionSave" />
                </div>

                <!-- 计划名称 -->
                <div class="com_box pd_20 mt_12">
                    <div class="market_title">计划名称</div>
                    <PlanName ref="planName" :createform="createform" :createRules="createRules" :planKeyWord="planKeyWord" @sessionSave="sessionSave" />
                    <BuildType :createform="createform" @sessionSave="sessionSave" />
                </div>
            </el-form>
        </div>
        <ThreeNext :is_three_true="is_three_true" @cancelCreation="cancelCreation" @preStep="preStep" @submitForm="submitForm" />
        <NextCheck ref="next_ref" :dataForm="dataForm" />
        <!-- <div class="create_footer com_box" style="margin-top:12px">
            <el-button plain class="el-button-width plain_red" size="small" @click="cancelCreation">取消创建</el-button>
            <el-button plain class="el-button-width" size="small" @click="preStep">上一步</el-button>
            <el-button type="primary" class="el-button-width" size="small" @click="submitForm('createform')">下一步</el-button>
        </div> -->
    </div>
</template>

<script>
import BudgetModel from "./BudgetModel";
import AddBulkBid from "./AddBulkBid";
import AudienceModel from "./AudienceModel";
import TimeSlot from "./TimeSlot";
import SaveModelName from "./SaveModelName";
import AddMateri from "./AddMateri";
import EditMateri from "./EditMateri";
import AddPicture from "./AddPicture";
import EditPicture from "./EditPicture";
import EditCardInfo from "./EditCardInfo";
import AddMoreWord from "./AddMoreWord";
import BatchAddIndustry from "./BatchAddIndustry";
import IndustryModel from "./IndustryModel";
import CreatTitleModel from "./CreatTitleModel";
import BatchAddTitle from "./BatchAddTitle";
import BatchAddCreatTitle from "./BatchAddCreatTitle";
import citysOptions from "../../assets/js/citys2";
import countyOptions from "../../assets/js/county2";
import HeadStep from "./model/HeadStep";

import CreateType from "./model/CreateType";

// 预算
import BudgetList from "./model/BudgetList"; //模板
import ReleaseDate from "./model/ReleaseDate"; //投放日期
import DateRange from "./model/DateRange"; //日期范围
import ReleaseDuration from "./model/ReleaseDuration"; //投放时长
import LaunchPeriod from "./model/LaunchPeriod"; //投放时段
import BudgetDay from "./model/BudgetDay"; //日预算
import BudgetPrice from "./model/BudgetPrice"; //出价
import Coupon from "./model/Coupon"; //优惠券

// 定向
import AudienceList from "./model/AudienceList"; //模板
import AudienceArea from "./model/AudienceArea"; //地域
import AudienceNews from "./model/AudienceNews"; //新客定向
import AudienceSex from "./model/AudienceSex"; //性别
import AudienceAge from "./model/AudienceAge"; //年龄
import AudienceTalent from "./model/AudienceTalent"; //达人
import AudienceCrowd from "./model/AudienceCrowd"; //人群
import AudienceExtend from "./model/AudienceExtend"; //放量
import AudiencePlatform from "./model/AudiencePlatform"; //平台
import AudienceIntention from "./model/AudienceIntention"; //兴趣
import AudienceNetwork from "./model/AudienceNetwork"; //网络

// 创意
import CreativeList from "./model/CreativeList"; //模板
import CreativeWay from "./model/CreativeWay"; //形式
import CreativeType from "./model/CreativeType"; //类型
import CreativeContent from "./model/CreativeContent"; //内容
import CreativeHide from "./model/CreativeHide"; //主页隐藏
// 标题
import TitleList from "./model/TitleList"; //模板
import TitleContent from "./model/TitleContent"; //内容

// 分类
import ClassifyList from "./model/ClassifyList"; //模板
import ClassifyType from "./model/ClassifyType"; //分类
import ClassifyTag from "./model/ClassifyTag"; //标签

import PlanName from "./model/PlanName"; //计划名称
import BuildType from "./model/BuildType"; //生成方式

import ThreeNext from "./model/ThreeNext"; //下一步
import NextCheck from "./model/NextCheck"; //下一步
export default {
    components: {
        BudgetModel,
        AddBulkBid,
        AudienceModel,
        TimeSlot,
        SaveModelName,
        AddMateri,
        EditMateri,
        AddPicture,
        EditPicture,
        EditCardInfo,
        AddMoreWord,
        BatchAddIndustry,
        IndustryModel,
        CreatTitleModel,
        BatchAddCreatTitle,
        BatchAddTitle,
        HeadStep,
        CreateType,

        // 预算
        BudgetList,
        ReleaseDate,
        DateRange,
        ReleaseDuration,
        LaunchPeriod,
        BudgetDay,
        BudgetPrice,
        Coupon,
        // 定向
        AudienceList,
        AudienceArea,
        AudienceNews,
        AudienceSex,
        AudienceAge,
        AudienceTalent,
        AudienceCrowd,
        AudienceExtend,
        AudiencePlatform,
        AudienceIntention,
        AudienceNetwork,
        // 创意
        CreativeList,
        CreativeWay,
        CreativeType,
        CreativeContent,
        CreativeHide,
        // 标题
        TitleList,
        TitleContent,
        // 分类
        ClassifyList,
        ClassifyType,
        ClassifyTag,

        PlanName,
        BuildType,

        // 下一步
        ThreeNext,
        NextCheck,
    },
    props: ["dataForm"],
    name: "",
    computed: {
        // 优惠券显示
        isShowCoupon() {
            let is_show = false;
            if (this.createform.delivery.smart_bid_type == "SMART_BID_CUSTOM") {
                if (
                    this.createform.external_action ==
                        "AD_CONVERT_TYPE_LIVE_SUCCESSORDER_ACTION" ||
                    this.createform.external_action ==
                        "AD_CONVERT_TYPE_LIVE_SUCCESSORDER_PAY" || 
                    this.createform.external_action ==
                        "AD_CONVERT_TYPE_LIVE_SUCCESSORDER_PAY_7DAYS" ||    
                    this.createform.deep_external_action =='AD_CONVERT_TYPE_LIVE_PAY_ROI' 
                ) {
                    is_show = true
                }
            }
            return is_show
        },
    },
    data() {
        var checkBudget = (rule, value, callback) => {
            let reg =
                /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
            if (!reg.test(value)) {
                return callback(
                    new Error("预算不少于300元，不超过9999999元，请正确输入")
                );
            } else if (value < 300 || value > 9999999) {
                return callback(
                    new Error("预算不少于300元，不超过9999999元，请正确输入")
                );
            } else if (
                this.createform.delivery.budget_mode == "BUDGET_MODE_TOTAL"
            ) {
                let date_time = this.createform.delivery.delivery_time;
                if (date_time.length > 0) {
                    let s1 = date_time[0];
                    let s2 = date_time[1];
                    s1 = new Date(s1.replace(/-/g, "/"));
                    s2 = new Date(s2.replace(/-/g, "/"));
                    let days = s2.getTime() - s1.getTime();
                    let time = parseInt(days / (1000 * 60 * 60 * 24)) + 1;

                    if (value < time * 100) {
                        return callback(new Error("预算不少于投放天数*100元"));
                    } else {
                        callback();
                    }
                } else {
                    callback();
                }
            } else {
                callback();
            }
        };
        var checkCpabid = (rule, value, callback) => {
            let reg =
                /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
            if (!reg.test(value)) {
                return callback(new Error("出价不少于0.1元，不超过10000元"));
            } else if (value < 0.1 || value > 10000) {
                return callback(new Error("出价不少于0.1元，不超过10000元"));
            } else if (
                Number(value) > Number(this.createform.delivery.budget)
            ) {
                return callback(new Error("出价不得高于预算"));
            } else {
                callback();
            }
        };

        var checkRoi = (rule, value, callback) => {
            let reg =
                /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
            if (!reg.test(value)) {
                return callback(new Error("不少于0.01元，不超过100元"));
            } else if (value < 0.01 || value > 100) {
                return callback(new Error("不少于0.01元，不超过100元"));
            } else {
                callback();
            }
        };

        var checkArea = (rule, value, callback) => {
            if (this.createform.audience.cityHasCheck.length > 200) {
                return callback(new Error("地域不能超过200个"));
            } else {
                callback();
            }
        };

        var checkTitok = (rule, value, callback) => {
            if (value.length > 30) {
                return callback(new Error("抖音达人不能超过30个"));
            } else {
                callback();
            }
        };

        var checkAction = (rule, value, callback) => {
            if (value.length > 350) {
                return callback(new Error("行为意向不能超过350个"));
            } else {
                callback();
            }
        };

        var checkInterest = (rule, value, callback) => {
            if (value.length > 350) {
                return callback(new Error("兴趣意向不能超过350个"));
            } else {
                callback();
            }
        };

        var checkTitleValue = (rule, value, callback) => {
            // let ref2 = /(?<=\{)(.+?)(?=\})/g;
            let wordList = this.keyWordList;
            let arr = [];
            let arrAll = [];
            let ref2 = /\{(.+?)\}/g; //获取花括号里面的内容-全局
            let ref = /\{(.+?)\}/; //获取花括号里面的内容
            let con = value.replace(/[^\{^\}]/g, "");
            let left = [];
            let right = [];
            let str = value.match(ref2);
            for (let i in con) {
                if (con[i] === "{") {
                    left.push(con[i]);
                } else {
                    right.push(con[i]);
                }
            }
            for (let i in str) {
                let text = str[i].match(ref);
                arrAll.push(text[1]);
            }
            for (let i in arrAll) {
                for (let a in wordList) {
                    if (arrAll[i] == wordList[a].name) {
                        arr.push({
                            word_id: wordList[a].creative_word_id,
                            dict_name: wordList[a].name,
                            default_word: wordList[a].default_word,
                        });
                    }
                }
            }
            let flag = arrAll.every((a) => {
                return wordList.some((b) => a == b.name);
            });
            let flag2 = left.length == right.length;
            if (!flag) {
                return callback(new Error("输入的动态词包不存在"));
            } else if (!flag2) {
                return callback(new Error("标题不允许带有{的符号"));
            } else if (arr.length > 2) {
                return callback(new Error("最多只能插入2个创意包"));
            } else {
                callback();
            }
        };

        var checkPlanValue = (rule, value, callback) => {
            // let ref2 = /(?<=\{)(.+?)(?=\})/g;
            let wordList = this.planKeyWord;
            let arr = [];
            let arrAll = [];
            let ref2 = /\{(.+?)\}/g; //获取花括号里面的内容-全局
            let ref = /\{(.+?)\}/; //获取花括号里面的内容
            let con = value.replace(/[^\{^\}]/g, "");
            let left = [];
            let right = [];
            let str = value.match(ref2);
            for (let i in con) {
                if (con[i] === "{") {
                    left.push(con[i]);
                } else {
                    right.push(con[i]);
                }
            }
            for (let i in str) {
                let text = str[i].match(ref);
                arrAll.push(text[1]);
            }
            for (let i in arrAll) {
                for (let a in wordList) {
                    if (arrAll[i] == wordList[a].name) {
                        arr.push({
                            word_id: wordList[a].creative_word_id,
                            dict_name: wordList[a].name,
                            default_word: wordList[a].default_word,
                        });
                    }
                }
            }
            let flag = arrAll.every((a) => {
                return wordList.some((b) => a == b.name);
            });
            let flag2 = left.length == right.length;
            if (!flag) {
                return callback(new Error("输入的动态词包不存在"));
            } else if (!flag2) {
                return callback(new Error("不允许带有{的符号"));
            } else {
                callback();
            }
        };
        return {
            blurIndex: null,
            is_three_true: false,
            planKeyWord: [],
            cityData: [],
            citysList: [],
            countryList: [],
            pickerOptions: {
                disabledDate(time) {
                    return time.getTime() < Date.now() - 8.64e7; //如果没有后面的-8.64e7就是不可以选择今天的
                },
            },
            value: "",
            titokResh: 0, //重置达人key
            industryKey: 100, //重置创意分类key
            cityOptions: [], //城市列表
            countyOptions: [], //区县列表
            keyWordFour: [], //创意词包
            keyWordList: [], //更多创意词包
            industryList: [], //创意分类
            industryName: "", //创意标签
            hotWordList: [], //精选热词列表
            hotWrodQuery: "", //精选热词搜索
            crowdQuery: "", //自定义人群包搜索
            isHotWordShow: false,
            hotWrod_loadding: false,
            titok_loadding: false,
            talent_loadding: false,
            pt_loadding: false,
            zdy_loadding: false,
            als_loadding: false,
            aky_loadding: false,
            ils_loadding: false,
            iky_loadding: false,
            radio15: "1",
            createform: {
                external_action: "", //转化目标
                creative_material_mode: "CUSTOM_CREATIVE", //创意类型
                creative_way: "LIVE", //创意形式
                creative_auto_generate: 1, //是否生成更多创意
                is_homepage_hide: 1, //抖音主页是否隐藏视频
                deep_external_action: "", //深度转化目标
                roi_goal: "", //支付ROI目标
                deep_bid_type: "MIN", //深度出价方式
                type: "", //生产方式
                queuename: "",
                //预算列表
                budget_list: [
                    {
                        model_name: "用户出价1",
                        smart_bid_type: "SMART_BID_CUSTOM",
                        cost_control: false,
                        flow_control_mode: "FLOW_CONTROL_MODE_FAST",
                        budget_mode: "BUDGET_MODE_DAY",
                        budget: "300",
                        cpa_bid: "300",
                        schedule_fixed_range: "2",
                        video_schedule_type: "SCHEDULE_FROM_NOW",
                        delivery_time: [],
                        start_time: "",
                        end_time: "",
                        launch_period: "1",
                        schedule_time_value: "",
                        qcpx_mode:"QCPX_MODE_OFF"
                    },
                ],
                budget_active: 0,
                //预算和出价
                delivery: {
                    model_name: "",
                    smart_bid_type: "SMART_BID_CUSTOM", //投放方式
                    cost_control: false, //成本控制
                    flow_control_mode: "FLOW_CONTROL_MODE_FAST", //投放速度
                    budget_mode: "BUDGET_MODE_DAY", //预算类型
                    budget: "300", //预算
                    cpa_bid: "300", //出价
                    schedule_fixed_range: "2", //固定时长
                    video_schedule_type: "SCHEDULE_FROM_NOW", //投放日期
                    delivery_time: [], //开始结束日期
                    start_time: "", //开始时间
                    end_time: "", //结束时间
                    launch_period: "1", //投放时段
                    schedule_time_value: "",
                    qcpx_mode:"QCPX_MODE_OFF"
                },

                // 定向人群列表
                audience_list: [
                    {
                        model_name: "定向人群1",
                        audience_mode: "AUTO", //智能推荐
                        isAllCity: false, //城市是否全选
                        district: "NONE", //城市
                        location_type: "CURRENT",
                        cityVal: [], //已选城市
                        cityHasCheck: [],
                        cityAllValue: [], //地域提交值
                        gender: "NONE", //性别
                        age: [], //年龄
                        awemeRadio: "1", //抖音达人切换
                        recomentRadio: "CLASS", //抖音达人切换
                        aweme_fan_behaviors: ["FOLLOWED_USER"], //已选抖音用户行为类型
                        aweme_fan_behaviors_days: "", //抖音达人互动用户行为天数
                        category_id: "", //推荐达人ID
                        category_text: "", //推荐名称
                        titokQuery: "", //抖音达人搜索
                        tiktokTypeOption: [], //达人分类列表
                        tiktokTypeCheck: [], //已选达人分类
                        tiktokTypeVal: [], //已选达人分类绑定值
                        titokTalentList: [], //抖音达人列表
                        titokTalentVal: [], //抖音达人绑定值ID
                        titokTalentText: [], //抖音达人显示值
                        tiktokAllCheck: [], //抖音达人总选
                        back_id: "", //返回达人ID
                        back_text: "", //返回达人名称
                        crowdRadio: "1", //更多人群切换
                        crowdTab: "1",
                        crowdDrop: "ALL",
                        plartformCrow: [], //平台精选人群列表
                        customCrow: [], //自定义人群列表
                        plartformVal: [], //平台精选人群绑定值
                        plartformText: [], //已选平台精选人群
                        customCrowdText: [], //已选自定义人群
                        allCrowdCheck: [], //人群总选
                        auto_extend_enabled: 0, //是否开启智能投放
                        auto_extend_targets: [], //已选智能投放绑定值
                        auto_extend_text: [], //已选智能投放列表
                        smart_interest_action: "", //行为兴趣类型
                        action_scene: ["E-COMMERCE", "NEWS", "APP"], //行为场景
                        actionTab: "1",
                        interestTab: "1",
                        action_days: "30", //行为天数
                        actionList: [], //行为类目列表
                        action_val: [], //行为类目绑定值
                        action_text: [], //行为类目已选值
                        action_key_list: [], //行为类目关键词列表
                        action_key_text: [], //行为类目已选关键词
                        actionAllCheck: [], //行为类目词总选值
                        actionKeyText: "", //已选行为类目
                        interestList: [], //兴趣类目列表
                        interest_val: [], //兴趣类目绑定值
                        interest_text: [], //兴趣类目已选值
                        interest_key_list: [], //兴趣关键词列表
                        interest_key_text: [], //兴趣已选关键词
                        interestAllCheck: [], //兴趣总选值
                        interestKeyText: "", //已选兴趣类目
                        age_null: "1",
                        ac: [], //网络
                        ac_null: "1",
                        platform: "", //平台
                        exclude_limited_region: 0, //排除限定地区
                        new_customer: "NONE", //新客定向
                    },
                ],

                audience_active: 0,
                // 定向人群数据
                audience: {
                    model_name: "",
                    audience_mode: "AUTO", //智能推荐
                    isAllCity: false, //城市是否全选
                    district: "NONE", //城市
                    location_type: "CURRENT",
                    cityVal: [], //已选城市
                    cityHasCheck: [],
                    cityAllValue: [], //地域提交值
                    gender: "NONE", //性别
                    age: [], //年龄
                    awemeRadio: "1", //抖音达人切换
                    recomentRadio: "CLASS", //抖音达人切换
                    aweme_fan_behaviors: ["FOLLOWED_USER"], //已选抖音用户行为类型
                    aweme_fan_behaviors_days: "", //抖音达人互动用户行为天数
                    category_id: "", //推荐达人ID
                    category_text: "", //推荐名称
                    titokQuery: "", //抖音达人搜索
                    tiktokTypeOption: [], //达人分类列表
                    tiktokTypeCheck: [], //已选达人分类
                    tiktokTypeVal: [], //已选达人分类绑定值
                    titokTalentList: [], //抖音达人列表
                    titokTalentVal: [], //抖音达人绑定值ID
                    titokTalentText: [], //抖音达人显示值
                    tiktokAllCheck: [], //抖音达人总选
                    back_id: "", //返回达人ID
                    back_text: "", //返回达人名称
                    crowdRadio: "1", //更多人群切换
                    crowdTab: "1",
                    crowdDrop: "ALL",
                    plartformCrow: [], //平台精选人群列表
                    customCrow: [], //自定义人群列表
                    plartformVal: [], //平台精选人群绑定值
                    plartformText: [], //已选平台精选人群
                    customCrowdText: [], //已选自定义人群
                    allCrowdCheck: [], //人群总选
                    auto_extend_enabled: 0, //是否开启智能投放
                    auto_extend_targets: [], //已选智能投放绑定值
                    auto_extend_text: [], //已选智能投放列表
                    smart_interest_action: "", //行为兴趣类型
                    action_scene: ["E-COMMERCE", "NEWS", "APP"], //行为场景
                    actionTab: "1",
                    interestTab: "1",
                    action_days: "30", //行为天数
                    actionList: [], //行为类目列表
                    action_val: [], //行为类目绑定值
                    action_text: [], //行为类目已选值
                    action_key_list: [], //行为类目关键词列表
                    action_key_text: [], //行为类目已选关键词
                    actionAllCheck: [], //行为类目词总选值
                    actionKeyText: "", //已选行为类目
                    interestList: [], //兴趣类目列表
                    interest_val: [], //兴趣类目绑定值
                    interest_text: [], //兴趣类目已选值
                    interest_key_list: [], //兴趣关键词列表
                    interest_key_text: [], //兴趣已选关键词
                    interestAllCheck: [], //兴趣总选值
                    interestKeyText: "", //已选兴趣类目
                    age_null: "1",
                    ac: [], //网络
                    ac_null: "1",
                    platform: "", //平台
                    exclude_limited_region: 0, //排除限定地区
                    new_customer: "NONE", //新客定向
                },

                creatinfo_active: 0,
                creatinfo_list: [
                    {
                        model_name: "创意组1",
                        creative: [],
                    },
                ],
                // 制作创意
                creatinfo: {
                    model_name: "",
                    creative: [],
                },

                creattitle_active: 0,
                creattitle_list: [
                    {
                        model_name: "标题组1",
                        title: [
                            {
                                title: "",
                                dynamic_words: [],
                            },
                        ],
                    },
                ],
                // 创意标题
                creattitle: {
                    model_name: "",
                    title: [
                        {
                            title: "",
                            dynamic_words: [],
                        },
                    ],
                },

                // 卡片
                card: {
                    car_img: null,
                    car_name: "视频同款商品",
                    car_tag: ["商家倾情推荐"],
                    car_link: "查看详情",
                    is_fisrtchoid: 1,
                    picture_name: "",
                },

                // 创意分类
                industry_active: 0,
                industry_list: [
                    {
                        model_name: "创意分类1",
                        industryValue: [],
                        ad_keywords: [],
                        first_industry_id: "",
                        second_industry_id: "",
                        third_industry_id: "",
                    },
                ],
                industryClass: {
                    model_name: "创意分类1",
                    industryValue: [],
                    ad_keywords: [],
                    first_industry_id: "",
                    second_industry_id: "",
                    third_industry_id: "",
                },

                // 计划名称
                name: "",
                exp_name: "",
            },

            createRules: {
                checkTitle: [
                    {
                        required: true,
                        message: "请输入",
                        trigger: ["blur", "change"],
                    },
                    {
                        min: 5,
                        max: 55,
                        message: "长度在 5 到 55 个字符",
                        trigger: ["blur", "change"],
                    },
                    { validator: checkTitleValue, trigger: ["blur", "change"] },
                ],
                checkRoi: [
                    { validator: checkRoi, trigger: ["blur", "change"] },
                ],
                "delivery.budget": [
                    { validator: checkBudget, trigger: ["blur", "change"] },
                ],
                "delivery.cpa_bid": [
                    { validator: checkCpabid, trigger: ["blur", "change"] },
                ],
                "audience.cityVal": [
                    {
                        required: true,
                        message: "请选择地域",
                        trigger: ["blur", "change"],
                    },
                    { validator: checkArea, trigger: ["blur", "change"] },
                ],
                "audience.tiktokAllCheck": [
                    {
                        required: true,
                        message: "请选择抖音达人",
                        trigger: ["blur", "change"],
                    },
                    { validator: checkTitok, trigger: ["blur", "change"] },
                ],
                "audience.allCrowdCheck": [
                    {
                        required: true,
                        message: "请选择人群",
                        trigger: ["blur", "change"],
                    },
                ],
                "audience.auto_extend_text": [
                    {
                        required: true,
                        message: "请选择智能投放",
                        trigger: ["blur", "change"],
                    },
                ],
                "audience.actionAllCheck": [
                    {
                        required: true,
                        message: "请选择行为意向",
                        trigger: ["blur", "change"],
                    },
                    { validator: checkAction, trigger: ["blur", "change"] },
                ],
                "audience.interestAllCheck": [
                    {
                        required: true,
                        message: "请选择兴趣意向",
                        trigger: ["blur", "change"],
                    },
                    { validator: checkInterest, trigger: ["blur", "change"] },
                ],
                "creatinfo.creative": [
                    {
                        required: true,
                        message: "请添加创意内容",
                        trigger: ["blur", "change"],
                    },
                ],
                "industryClass.industryValue": [
                    {
                        required: false,
                        message: "请选择创意分类",
                        trigger: ["blur", "change"],
                    },
                ],
                "industryClass.ad_keywords": [
                    {
                        required: false,
                        message: "请选择创意标签",
                        trigger: ["blur", "change"],
                    },
                ],
                checkPlan: [
                    {
                        required: true,
                        message: "请输入",
                        trigger: ["blur", "change"],
                    },
                    { validator: checkPlanValue, trigger: ["blur", "change"] },
                ],
            },
        };
    },
    created() {
        // this.cityData = citysData
        // this.getCityDatas()
        // this.getCountryData()
        this.cityOptions = citysOptions;
        this.countyOptions = countyOptions;
        this.createform = this.dataForm.createform;
        this.createform.delivery =
            this.createform.budget_list[this.createform.budget_active];
        this.createform.audience =
            this.createform.audience_list[this.createform.audience_active];
        this.createform.industryClass =
            this.createform.industry_list[this.createform.industry_active];
        this.createform.creatinfo =
            this.createform.creatinfo_list[this.createform.creatinfo_active];
        this.createform.creattitle =
            this.createform.creattitle_list[this.createform.creattitle_active];
        this.dataForm.createform.card.car_img = this.dataForm.createform.card
            .car_img
            ? this.dataForm.createform.card.car_img
            : this.dataForm.tableData[0].hasShop.img;
        this.dataForm.createform.card.picture_name = this.dataForm.createform
            .card.picture_name
            ? this.dataForm.createform.card.picture_name
            : this.dataForm.tableData[0].hasShop.product_name +
              "_" +
              this.dataForm.tableData[0].hasShop.product_id;
        this.dataForm.createform.card.picture_name = this.dataForm.createform
            .card.picture_name
            ? this.dataForm.createform.card.picture_name
            : this.dataForm.tableData[0].hasShop.product_name +
              "_" +
              this.dataForm.tableData[0].hasShop.product_id;
        this.getCoupon()
        this.getAwemecategory();
        this.getPlamCrow();
        this.getCustomCrow();
        // this.getActionList();
        // this.getInterestList();
        this.getKeyWord();
        this.getIndustryList();
        if (this.createform.audience.category_id) {
            this.getRecommendedTalent();
        }
        if (this.createform.audience.titokQuery) {
            this.remoteMethodTitok();
        }
        // if (this.createform.audience.actionKeyText) {
        //     this.getActionKey();
        // }
        // if (this.createform.audience.interestKeyText) {
        //     this.getInterestKey();
        // }
        this.planKeyWord = [
            {
                name: "日期",
                default_name: this.getCurrentDate(),
                key: "{日期}",
                disabled: false,
            },
            {
                name: "投放方式",
                default_name:
                    this.createform.delivery.smart_bid_type ==
                    "SMART_BID_CUSTOM"
                        ? "控制成本投放"
                        : "放量投放",
                key: "{投放方式}",
                disabled: false,
            },
            {
                name: "转化目标",
                default_name: this.getExternalText(),
                key: "{转化目标}",
                disabled: false,
            },
            {
                name: "预算包名",
                default_name: this.createform.delivery.model_name,
                key: "{预算包名}",
                disabled: false,
            },
            {
                name: "定向包名",
                default_name: this.createform.audience.model_name,
                key: "{定向包名}",
                disabled: false,
            },
            {
                name: "创意分类包名",
                default_name: this.createform.industryClass.model_name,
                key: "{创意分类包名}",
                disabled: false,
            },
            {
                name: "创意组包名",
                default_name: this.createform.creatinfo.model_name,
                key: "{创意组包名}",
                disabled: false,
            },
            {
                name: "标题组包名",
                default_name: this.createform.creattitle.model_name,
                key: "{标题组包名}",
                disabled: false,
            },
        ];
    },
    methods: {
        //选择投放设置
        changeExternal(v) {
            this.planKeyWord[2].default_name = this.getExternalText();
            this.createform.deep_external_action = "";
            this.sessionSave();
        },

        // 选择支付ROI
        payRoi(v) {
            if (v == "AD_CONVERT_TYPE_LIVE_PAY_ROI") {
                this.createform.deep_bid_type = "MIN";
            }
            this.planKeyWord[2].default_name = this.getExternalText();
            this.sessionSave();
        },

        // 投放方式
        changeSmartType() {
            if (
                this.createform.delivery.smart_bid_type ==
                "SMART_BID_CONSERVATIVE"
            ) {
                this.createform.delivery.budget_mode = "BUDGET_MODE_DAY";
                this.createform.delivery.cost_control = false;
                this.createform.deep_external_action = "";
            }
            let text =
                this.createform.delivery.smart_bid_type == "SMART_BID_CUSTOM"
                    ? "控制成本投放"
                    : "放量投放";
            this.changePlanKey(1, text);
            this.sessionSave();
        },

        // 严格控制成本
        changeCostControl(v) {
            if (v) {
                this.createform.deep_external_action = "";
            }
            this.sessionSave();
        },

        //保存模板
        saveModel(item, index, type) {
            let that = this;
            if (type == 1) {
                this.$refs.budRef.budgetCheck(index, function () {
                    const attr = {
                        dialogVsb: true,
                        type: type,
                        content: item,
                    };
                    that.$bus.emit("saveModel", attr);
                });
            } else if (type == 2) {
                this.$refs.audienceRef.ActionInterestCheck(index, function () {
                    const attr = {
                        dialogVsb: true,
                        type: type,
                        content: item,
                    };
                    that.$bus.emit("saveModel", attr);
                });
            } else if (type == 4) {
                this.$refs.titleRef.creattitleCheck(index, function () {
                    const attr = {
                        dialogVsb: true,
                        type: type,
                        content: item,
                    };
                    that.$bus.emit("saveModel", attr);
                });
            } else if (type == 5) {
                this.$refs.classRef.industryCheck(index, function () {
                    const attr = {
                        dialogVsb: true,
                        type: type,
                        content: item,
                    };
                    that.$bus.emit("saveModel", attr);
                });
            }
        },

        //判断优惠券权限
        async getCoupon() {
            const { data: res } = await this.$http.post(
                "launch/Getinfo/allowCoupon",
                {
                    advertiser_id:this.dataForm.tableData[0].hasAdver.advertiser_id,
                    marketing_goal: this.dataForm.market,
                    campaign_scene: this.dataForm.campaign_scene,
                    marketing_scene: 'FEED',
                    aweme_ids: this.dataForm.tableData[0].hasAchor.aweme_id,
                }
            );
            if (res.code !== 200) {
                this.$message.error(res.msg);
                return;
            } else {
                let is_coupon = false;
                if(res.data.aweme_allow_coupon.length>0){
                    let obj = res.data.aweme_allow_coupon[0]
                    if(res.data.adv_allow_coupon && obj.allow_coupon){
                        is_coupon = true
                    }
                }
                this.is_coupon =  is_coupon
            }
        },

        //获取抖音类目列表
        async getAwemecategory() {
            this.titok_loadding = true;
            const { data: res } = await this.$http.post(
                "launch/Getinfo/get_awemecategory",
                {
                    advertiser_id:
                        this.dataForm.tableData[0].hasAdver.advertiser_id,
                    behaviors: this.createform.audience.aweme_fan_behaviors,
                }
            );
            if (res.code !== 200) {
                this.$message.error(res.msg);
                this.titok_loadding = false;
                return;
            } else {
                this.titok_loadding = false;
                ++this.titokResh;
                this.createform.audience.tiktokTypeOption = this.getTreeData(
                    res.data
                );
            }
            this.sessionSave();
        },

        //获取推荐达人列表
        async getRecommendedTalent() {
            this.talent_loadding = true;
            const { data: res } = await this.$http.post(
                "launch/Getinfo/get_awemecategorytoauthor",
                {
                    advertiser_id:
                        this.dataForm.tableData[0].hasAdver.advertiser_id,
                    category_id: this.createform.audience.category_id,
                }
            );
            if (res.code !== 200) {
                this.talent_loadding = false;
                this.$message.error(res.msg);
                return;
            } else {
                this.talent_loadding = false;
                this.createform.audience.titokTalentList = res.data;
            }
            this.sessionSave();
        },

        // 搜索抖音达人
        async remoteMethodTitok() {
            if (!this.createform.audience.titokQuery) {
                return;
            }
            this.createform.audience.recomentRadio = "TITKOT";
            this.talent_loadding = true;
            const { data: res } = await this.$http.post(
                "launch/Getinfo/aweme_info_search",
                {
                    query_word: this.createform.audience.titokQuery,
                    behaviors: this.createform.audience.aweme_fan_behaviors,
                }
            );
            if (res.code !== 200) {
                this.talent_loadding = false;
                this.$message.error(res.msg);
                return;
            } else {
                this.talent_loadding = false;
                this.createform.audience.category_id = "";
                this.createform.audience.titokTalentList = res.data;
            }
            this.sessionSave();
        },

        // 过滤空数组
        getTreeData(data) {
            if (!data || !data.length) return;
            for (var i = 0; i < data.length; i++) {
                if (data[i].children && data[i].children.length < 1) {
                    data[i].children = null;
                } else {
                    this.getTreeData(data[i].children);
                }
            }
            return data;
        },

        //获取平台精选人群包
        async getPlamCrow() {
            this.pt_loadding = true;
            const { data: res } = await this.$http.post(
                "launch/Getinfo/get_audienceslist",
                {
                    advertiser_id:
                        this.dataForm.tableData[0].hasAdver.advertiser_id,
                    type: 0,
                }
            );
            if (res.code !== 200) {
                this.pt_loadding = false;
                this.$message.error(res.msg);
                return;
            } else {
                this.pt_loadding = false;
                this.createform.audience.plartformCrow =
                    res.data.retargeting_tags;
            }
            this.$refs.crowdRef.checkPlartCrowd(
                this.createform.audience.plartformVal
            );
            this.sessionSave();
        },

        //获取自定义人群包
        async getCustomCrow() {
            this.zdy_loadding = true;
            const { data: res } = await this.$http.post(
                "launch/Getinfo/get_audienceslist",
                {
                    advertiser_id:
                        this.dataForm.tableData[0].hasAdver.advertiser_id,
                    type: 1,
                }
            );
            if (res.code !== 200) {
                this.zdy_loadding = false;
                this.$message.error(res.msg);
                return;
            } else {
                this.zdy_loadding = false;
                let newArr = [];
                for (let i in res.data.retargeting_tags) {
                    for (let a in this.createform.audience.customCrowdText) {
                        if (
                            res.data.retargeting_tags[i].retargeting_tags_id ==
                            this.createform.audience.customCrowdText[a]
                                .retargeting_tags_id
                        ) {
                            res.data.retargeting_tags[i].retargeting_tags_op =
                                this.createform.audience.customCrowdText[
                                    a
                                ].retargeting_tags_op;
                            newArr.push(
                                this.createform.audience.customCrowdText[a]
                            );
                        }
                    }
                }
                this.createform.audience.customCrowdText = newArr;
                this.$refs.crowdRef.checkPlartCrowd(
                    this.createform.audience.plartformVal
                );
                this.createform.audience.customCrow = res.data.retargeting_tags;
            }
            this.sessionSave();
        },

        //获取行为类目词
        // async getActionList() {
        //     this.als_loadding = true;
        //     const { data: res } = await this.$http.post(
        //         "launch/Getinfo/get_interest_action",
        //         {
        //             advertiser_id:
        //                 this.dataForm.tableData[0].hasAdver.advertiser_id,
        //             action_scene: this.createform.audience.action_scene,
        //             action_days: this.createform.audience.action_days,
        //         }
        //     );
        //     if (res.code !== 200) {
        //         this.als_loadding = false;
        //         this.$message.error(res.msg);
        //         return;
        //     } else {
        //         this.als_loadding = false;
        //         this.createform.audience.actionList = res.data;
        //     }
        //     this.sessionSave();
        // },

        //获取行为类关键词
        // async getActionKey() {
        //     this.aky_loadding = true;
        //     const { data: res } = await this.$http.post(
        //         "launch/Getinfo/get_interest_keyword",
        //         {
        //             advertiser_id:
        //                 this.dataForm.tableData[0].hasAdver.advertiser_id,
        //             query_words: this.createform.audience.actionKeyText,
        //             action_scene: this.createform.audience.action_scene,
        //             action_days: this.createform.audience.action_days,
        //         }
        //     );
        //     if (res.code !== 200) {
        //         this.aky_loadding = false;
        //         this.$message.error(res.msg);
        //         return;
        //     } else {
        //         this.aky_loadding = false;
        //         for (let i in this.createform.audience.action_key_text) {
        //             for (let a in res.data) {
        //                 if (
        //                     this.createform.audience.action_key_text[i].id ==
        //                     res.data[a].id
        //                 ) {
        //                     res.data[a].check = true;
        //                 }
        //             }
        //         }
        //         this.createform.audience.action_key_list = res.data;
        //     }
        //     this.sessionSave();
        // },

        //获取兴趣类目
        // async getInterestList() {
        //     this.ils_loadding = true;
        //     const { data: res } = await this.$http.post(
        //         "launch/Getinfo/get_interest_category",
        //         {
        //             advertiser_id:
        //                 this.dataForm.tableData[0].hasAdver.advertiser_id,
        //         }
        //     );
        //     if (res.code !== 200) {
        //         this.ils_loadding = false;
        //         this.$message.error(res.msg);
        //         return;
        //     } else {
        //         this.ils_loadding = false;
        //         this.createform.audience.interestList = res.data;
        //     }
        //     this.sessionSave();
        // },

        //获取兴趣关键词
        // async getInterestKey() {
        //     this.iky_loadding = true;
        //     const { data: res } = await this.$http.post(
        //         "launch/Getinfo/get_category_keyword",
        //         {
        //             advertiser_id:
        //                 this.dataForm.tableData[0].hasAdver.advertiser_id,
        //             query_words: this.createform.audience.interestKeyText,
        //         }
        //     );
        //     if (res.code !== 200) {
        //         this.iky_loadding = false;
        //         this.$message.error(res.msg);
        //         return;
        //     } else {
        //         this.iky_loadding = false;
        //         for (let i in this.createform.audience.interest_key_text) {
        //             for (let a in res.data) {
        //                 if (
        //                     this.createform.audience.interest_key_text[i].id ==
        //                     res.data[a].id
        //                 ) {
        //                     res.data[a].check = true;
        //                 }
        //             }
        //         }
        //         this.createform.audience.interest_key_list = res.data;
        //     }
        //     this.sessionSave();
        // },

        // 选择创意形式
        changeCreativeWay() {
            this.createform.creative_material_mode = "CUSTOM_CREATIVE";
            this.createform.name = this.deletCreatIsCust();
            this.sessionSave();
        },

        // 切换创意类型
        changeCreativeMode() {
            this.createform.name = this.deletCreatIsCust();
            this.sessionSave();
        },

        //获取动态创意词包
        async getKeyWord() {
            const { data: res } = await this.$http.post(
                "launch/Getinfo/get_creative_word",
                {
                    advertiser_id:
                        this.dataForm.tableData[0].hasAdver.advertiser_id,
                }
            );
            if (res.code !== 200) {
                this.$message.error(res.msg);
                return;
            } else {
                this.keyWordList = res.data;
                this.keyWordFour = res.data.slice(0, 4);
            }
        },

        //创意词包验证-程序化
        changeWordTitle(val, index) {
            this.$nextTick(() => {
                let wordList = this.keyWordList;
                let arr = [];
                let arrAll = [];
                let ref2 = /\{(.+?)\}/g;
                let ref = /\{(.+?)\}/;
                let str = val.title.match(ref2);
                for (let i in str) {
                    let text = str[i].match(ref);
                    arrAll.push(text[1]);
                }
                for (let i in wordList) {
                    for (let a in arrAll) {
                        if (wordList[i].name == arrAll[a]) {
                            if (arr.length >= 2) {
                                return;
                            } else {
                                arr.push({
                                    word_id: wordList[i].creative_word_id,
                                    dict_name: wordList[i].name,
                                    default_word: wordList[i].default_word,
                                });
                            }
                        }
                    }
                }
                this.createform.creattitle.title[index].dynamic_words = arr;
                this.sessionSave();
            });
        },

        //获取行业列表
        async getIndustryList() {
            const { data: res } = await this.$http.post(
                "launch/Getinfo/industry_list"
            );
            if (res.code !== 200) {
                this.$message.error(res.msg);
                return;
            } else {
                this.industryList = this.treeData(res.data);
            }
        },
        // 创意分类树形结构
        treeData(arr) {
            let first = [];
            arr.forEach((item) => {
                if (item.level == 1) {
                    first.push(item);
                }
            });
            first.forEach((item) => {
                item.children = [];
                arr.forEach((i) => {
                    if (
                        item.first_industry_id == i.first_industry_id &&
                        i.level == 2
                    ) {
                        item.children.push(i);
                    }
                });
            });
            first.forEach((item) => {
                item.children.forEach((i) => {
                    i.children = [];
                    arr.forEach((a) => {
                        if (
                            i.second_industry_id == a.second_industry_id &&
                            a.level == 3
                        ) {
                            i.children.push(a);
                        }
                    });
                });
            });
            return first;
        },

        // 双向绑定改变计划名
        changePlanKey(index, name) {
            this.planKeyWord[index].default_name = name;
            this.sessionSave();
        },

        // 获取当前时间
        getCurrentDate() {
            let nowData = new Date();
            let year = nowData.getFullYear();
            let month =
                nowData.getMonth() + 1 < 10
                    ? "0" + (nowData.getMonth() + 1)
                    : nowData.getMonth() + 1;
            let date =
                nowData.getDate() < 10
                    ? "0" + nowData.getDate()
                    : nowData.getDate();
            let hh = nowData.getHours();
            let mm =
                nowData.getMinutes() < 10
                    ? "0" + nowData.getMinutes()
                    : nowData.getMinutes();
            let ss =
                nowData.getSeconds() < 10
                    ? "0" + nowData.getSeconds()
                    : nowData.getSeconds();
            let getData =
                year +
                "-" +
                month +
                "-" +
                date +
                "/" +
                hh +
                ":" +
                mm +
                ":" +
                ss;
            return getData;
        },

        getExternalText() {
            let text = "";
            let value = this.dataForm.createform.external_action;
            let value2 = this.createform.deep_external_action;
            if (value == "AD_CONVERT_TYPE_SHOPPING") {
                if (value2 == "AD_CONVERT_TYPE_LIVE_PAY_ROI") {
                    text = "支付roi";
                } else {
                    text = "商品购买";
                }
            } else if (value == "AD_CONVERT_TYPE_QC_FOLLOW_ACTION") {
                text = "粉丝提升";
            } else if (value == "AD_CONVERT_TYPE_QC_MUST_BUY") {
                text = "点赞评论";
            } else if (value == "AD_CONVERT_TYPE_LIVE_ENTER_ACTION") {
                text = "进入直播间";
            } else if (value == "AD_CONVERT_TYPE_LIVE_CLICK_PRODUCT_ACTION") {
                text = "直播间商品点击";
            } else if (value == "AD_CONVERT_TYPE_LIVE_SUCCESSORDER_ACTION") {
                text = "直播间下单";
            } else if (value == "AD_CONVERT_TYPE_LIVE_SUCCESSORDER_PAY") {
                text = "直播间成交";
            } else if (value == "AD_CONVERT_TYPE_NEW_FOLLOW_ACTION") {
                text = "直播间粉丝提升";
            } else if (value == "AD_CONVERT_TYPE_LIVE_COMMENT_ACTION") {
                text = "直播间评论";
            } else if (value == "AD_CONVERT_TYPE_LIVE_SUCCESSORDER_SETTLE") {
                text = "直播间结算";
            }
            if (value2 == "AD_CONVERT_TYPE_LIVE_PAY_ROI") {
                if (value == "AD_CONVERT_TYPE_LIVE_SUCCESSORDER_PAY") {
                    text = "直接支付ROI";
                } else if (
                    value == "AD_CONVERT_TYPE_LIVE_SUCCESSORDER_PAY_7DAYS"
                ) {
                    text = "7日总支付ROI";
                }
            }
            return text;
        },

        changeRoiType() {
            this.planKeyWord[2].default_name = this.getExternalText();
            this.sessionSave();
        },

        //删除自定义下对应的标题名称
        deletCreatIsCust() {
            let name = this.createform.name;
            if (this.createform.creative_material_mode == "CUSTOM_CREATIVE") {
                name = name.replace("{标题组包名}", "");
            }
            return name;
        },

        // 提交添加
        submitForm(formName) {
            this.$refs[formName].validate(async (valid) => {
                if (valid) {
                    this.createform.exp_name =
                        this.$refs.planName.getPlanNameExple();
                    window.sessionStorage.setItem(
                        "dataForm",
                        JSON.stringify(this.dataForm)
                    );
                    let createSubForm = this.getSubForm();
                    this.is_three_true = true;
                    const { data: res } = await this.$http.post(
                        "launch/Getinfo/planMarterVerify",
                        {
                            batch_create: createSubForm.batch_create,
                        }
                    );
                    if (res.code !== 200) {
                        this.is_three_true = false;
                        this.$message.error(res.msg);
                        return;
                    } else {
                        this.is_three_true = false;
                        this.$refs.next_ref.getData(res.data);
                    }
                    return;
                    this.dataForm.step = 4;
                } else {
                    this.is_three_true = false;
                    this.$message.error("请完善信息！");
                    return false;
                }
            });
        },

        getSubForm() {
            let createSubForm = {
                queuename: "",
                execution_time: "",
                batch_create: {
                    name: "", //计划名称
                    marketing_goal: "", //营销目标
                    promotion_way: "", //推广方式
                    deep_external_action: "", //深度转化目标
                    accounts: [], //账户列表
                    external_action: "", //转化目标
                    creative_material_mode: "", //创意类型
                    creative_way: "", //创意形式
                    creative_auto_generate: "", //是否生成更多创意
                    is_homepage_hide: "", //抖音主页是否隐藏视频
                    delivery: [], //预算和出价
                    audience: [], //定向人群
                    creative: [], //创意列表
                    title: [
                        [
                            {
                                title: "",
                                dynamic_words: [],
                            },
                        ],
                    ], //标题列表
                    card: {},
                    creativity_class: [], //创意类型
                },
                type: "", //生成方式
                source: "", //数据缓存
            };
            let batch_create = createSubForm.batch_create;
            let createform = this.dataForm.createform;
            //账户列表
            for (let i in this.dataForm.tableData) {
                batch_create.accounts.push({
                    campaign_id: this.dataForm.tableData[i].hasGroup.id,
                    advertiser_id:
                        this.dataForm.tableData[i].hasAdver.advertiser_id,
                    advertiser_name: this.dataForm.tableData[i].hasAdver.name,
                    aweme_id: this.dataForm.tableData[i].hasAchor.aweme_id,
                    aweme_name: this.dataForm.tableData[i].hasAchor.aweme_name,
                    aweme_img: this.dataForm.tableData[i].hasAchor.aweme_avatar,
                    product_id: this.dataForm.tableData[i].hasShop.product_id,
                    product_name:
                        this.dataForm.tableData[i].hasShop.product_name,
                    product_img: this.dataForm.tableData[i].hasShop.img,
                });
            }

            // 创意列表
            let creative = [];
            for (let i in createform.creatinfo_list) {
                let children = [];
                for (let a in createform.creatinfo_list[i].creative) {
                    children.push({
                        creative_name: createform.creatinfo_list[i].model_name, //模板名称
                        material_type:
                            createform.creatinfo_list[i].creative[a].material
                                .cate_type, //素材类型
                        material_source:
                            createform.creatinfo_list[i].creative[a].material
                                .material_source, //原数据类型
                        image_mode:
                            createform.creatinfo_list[i].creative[a].material
                                .cate_type == "video"
                                ? createform.creatinfo_list[i].creative[a]
                                      .material.image_mode
                                : "LARGE_VERTICAL", //文件类型
                        aweme_item_id: createform.creatinfo_list[i].creative[a]
                            .material.aweme_item_id
                            ? createform.creatinfo_list[i].creative[a].material
                                  .aweme_item_id
                            : "", //抖音视频ID
                        poster_url:
                            createform.creatinfo_list[i].creative[a].material
                                .img_url, //视频封面图地址
                        video_id:
                            createform.creatinfo_list[i].creative[a].material
                                .id, //素材ID
                        design_id:
                            createform.creatinfo_list[i].creative[a].material
                                .id, //素材库素材ID
                        image_url:
                            createform.creatinfo_list[i].creative[a].material
                                .cate_type == "video"
                                ? createform.creatinfo_list[i].creative[a]
                                      .material.material
                                : createform.creatinfo_list[i].creative[a]
                                      .material.material.url, //素材地址
                        image_name:
                            createform.creatinfo_list[i].creative[a].material
                                .material_name, //素材名称
                        poster_name:
                            createform.creatinfo_list[i].creative[a].material
                                .material_name, //素材名称
                        title: createform.creatinfo_list[i].creative[a].title, //标题
                        promotion_card_title:
                            createform.creatinfo_list[i].creative[a].card
                                .car_name, //推广卡片标题
                        promotion_card_selling_points:
                            createform.creatinfo_list[i].creative[a].card
                                .car_tag, //推广卡片卖点列表
                        promotion_card_image_name:
                            createform.creatinfo_list[i].creative[a].material
                                .material_name + "card", //推广卡片图片名称
                        promotion_card_image_url:
                            createform.creatinfo_list[i].creative[a].card
                                .car_img, //推广卡片图片地址
                        promotion_card_button_smart_optimization:
                            createform.creatinfo_list[i].creative[a].card
                                .is_fisrtchoid, //启用智能优选
                        promotion_card_action_button:
                            createform.creatinfo_list[i].creative[a].card
                                .car_link, //按钮文案
                        dynamic_words:
                            createform.creatinfo_list[i].creative[a]
                                .dynamic_words, //动态词包对象列表
                    });
                }
                creative.push(children);
            }
            if (
                createform.creative_way == "LIVE" &&
                this.dataForm.market == "LIVE_PROM_GOODS"
            ) {
                createSubForm.batch_create.creative = [[]];
            } else {
                createSubForm.batch_create.creative = creative;
            }
            return createSubForm;
        },

        sessionSave() {
            window.sessionStorage.setItem(
                "dataForm",
                JSON.stringify(this.dataForm)
            );
        },

        // 上一步
        preStep() {
            this.dataForm.step = 2;
            this.sessionSave();
        },

        // 跳转到第一步
        toStepOne() {
            this.dataForm.step = 1;
            this.sessionSave();
        },

        // 取消创建
        cancelCreation() {
            this.$confirm("是否取消？", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    sessionStorage.removeItem("dataForm");
                    this.$parent.dataForm = JSON.parse(
                        JSON.stringify(this.$parent.resetForm)
                    );
                })
                .catch(() => {});
        },
    },
};
</script>


<style scoped>
.create_footer {
    padding: 20px;
    text-align: right;
    box-shadow: 0px -2px 11px rgba(213, 210, 210, 0.23);
}
.market_title {
    font-size: 16px;
    color: #17233d;
    font-weight: bold;
    padding-left: 12px;
    position: relative;
    line-height: 22px;
    margin-bottom: 20px;
}
.market_title::after {
    content: "";
    position: absolute;
    height: 12px;
    width: 4px;
    background-color: #4475ff;
    border-radius: 5px;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
}
.mt_12 {
    margin-top: 12px;
}
.active {
    font-weight: bold;
}
.plan_header {
    padding: 20px;
    position: sticky;
    top: 0;
    z-index: 999;
}
.no_radius {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    padding-top: 0;
}
.user_tips {
    line-height: 25px;
    padding: 0 12px;
    background-color: rgba(165, 177, 209, 0.08);
    margin-left: 8px;
}
</style>
